﻿using FastORM.Applicaiton;
using FastORM.Enum;
using FastUtil.Config;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCore.Test.ORM
{
    [TestClass]
    public class BaseOperate
    {
        [TestMethod]
        public void Insert()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            //增
            Frame_User user = new Frame_User();
            user.UserGuid = "XXXXXX";
            user.LoginID = "yanpeng";
            user.Mobile = "18800001111";
            user.Age = 18;
            user.DisplayName = "颜鹏";
            user.Birthday = DateTime.Now;
            user.Gender = 1;
            user.Introduction = "XXXXXXXXXXXXXXXXX";
            user.Salary = 5356;
            dao.Insert(user);

        }
        [TestMethod]
        public void InsertBatch()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            List<Frame_User> UserList = new List<Frame_User>();
            for (int i = 0; i < 100; i++)
            {
                Frame_User userbatch = new Frame_User();
                userbatch.UserGuid = Guid.NewGuid().ToString();
                userbatch.LoginID = "yanpeng" + "_" + i;
                userbatch.Mobile = "18800001111";
                userbatch.Age = 18;
                userbatch.DisplayName = "颜鹏" + "_" + i;
                userbatch.Birthday = DateTime.Now;
                userbatch.Gender = 1;
                userbatch.Introduction = "XXXXXXXXXXXXXXXXX";
                userbatch.Salary = 5356;
                UserList.Add(userbatch);
            }
            dao.InsertBatch(UserList);
        }
        [TestMethod]
        public void DeleteEntity()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            Frame_User user = dao.Find<Frame_User>("DisplayName", "颜鹏_0");
            dao.Delete(user);
        }
        [TestMethod]
        public void DeleteWithKey()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            dao.Delete<Frame_User>("c99c3bf1-34a8-4688-acf3-3746b5d98f8f");
            dao.Delete<Frame_User>("DisplayName", "颜鹏_9");
        }
        [TestMethod]
        public void UpdateEntity()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            Frame_User user = dao.Find<Frame_User>("XXXXXX");
            user.LoginID = "yanpeng1111";
            dao.Update(user);
        }
        [TestMethod]
        public void UpdateEntityWithCoumns()
        {
            CommonDao dao = new CommonDao(DataBaseClass.MySql, AppConfigUtil.Configuration["ConnectionStrings:Base_ConnectionString"]);
            Frame_User user = dao.Find<Frame_User>("XXXXXX");
            user.Mobile = "155667";
            user.Age = 20;
            dao.Update(user,new string[] { "Age"});
        }

    }
}
